package br.indt.framework.ui.common;

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

import br.indt.framework.utils.StringUtils;

public class LabelWithTwoColor extends Label {
	
	private int newColorAt = 0;
	private int newColor = 0;
	private int endIndex = 0;
	
	public LabelWithTwoColor(String text, int index, int color, int endIndex) {
		super("twoColorLabel", text);
		newColorAt = index;
		newColor = color;
		this.endIndex = endIndex;
	}

	public LabelWithTwoColor(String text, int index, int color, int endIndex, boolean wrap, int maxLines, Icon icon) {
		super("twoColorLabel", text, wrap, maxLines, icon);
		newColorAt = index;
		newColor = color;
		this.endIndex = endIndex;
	}

	public void paint(Graphics g, int x, int y, int maxWidth, int maxHeight) {
		g.setColor(textColor);
		g.setFont(font);
		y += topMargin;
		x += leftMargin;
		int currentIndex = 0;
		if(lines > 0) {
			String txt = null;
			for(int i = 0; i < lines; i++) {
				txt = (String) textVector.elementAt(i);
				Vector split = StringUtils.split(txt, " ", true);
				int size = split.size();
				String tmp = null;
				int tmpX = x;
				for(int j = 0; j < size; j++) {
					tmp = (String) split.elementAt(j);
					g.drawString(tmp , tmpX, y, Graphics.TOP | Graphics.LEFT);
					tmpX += font.stringWidth(tmp);
					currentIndex += tmp.length();
					if(currentIndex >= endIndex) {
						g.setColor(textColor);
					} else if(currentIndex >= newColorAt) {
						g.setColor(newColor);
					}
				}
				y += font.getHeight() + LINE_GAP;
			}
		}
	}

	public void pressFire() {
		// TODO Auto-generated method stub
		
	}
	
}
